#ifndef Q1_H
#define Q1_H
#include <cstdlib>
#include <functional>
namespace q1 {
    static double gradient_descent_internal( double init , double step , std::function<double(double)> func ) {
        double x{init};
        double df{(func(x + 0.00001) - func(x)) / 0.00001};
        while (std::abs(df) > 0.00001) {
            x -= step * df;
            df = (func(x + 0.00001) - func(x)) / 0.00001;
        }
        return x;
    }
    template <typename T , typename F>
    T gradient_descent(T init, T step, F func) {
        return gradient_descent_internal(init ,step , func );
    }
    template <typename T , typename F>
    T gradient_descent(T init, T step) {
        return gradient_descent_internal(init ,step , F() );
    }
}
#endif //Q1_H